#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+10;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
template<typename A,typename B>
struct unmap{
    struct node{
        A u;B v;int nxt;
    };
    static const unsigned uN=20000003;
    vector<node>e;
    int head[uN];
    unmap(){memset(head,-1,sizeof(head));}
    bool count(A u){
        int hs=u%uN;
        for(int i=head[hs];~i;i=e[i].nxt)
            if(e[i].u==u) return 1;
        return 0;
    }
    B &operator[](A u){
        int hs=u%uN;
        for(int i=head[hs];~i;i=e[i].nxt)
            if(e[i].u==u) return e[i].v;
        e.push_back({u,B(),head[hs]}),head[hs]=e.size()-1;
        return e.back().v;
    }
};
unmap<int,int>cnt;
int a[maxn],b[maxn];
int main(void)
{
  int n,m;scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=1;i<=m;i++) scanf("%d",&b[i]);
  LL ans=0;
  for(int j=0;j<30;j++){
    for(int i=1;i<=m;i++){
        ans+=cnt[ b[i]^(1<<j)];
    }
    for(int i=1;i<=n;i++){
        cnt[a[i]^(1<<j)]++;
    }
  }
  printf("%lld\n",ans);
return 0;
}
